package my.jwds.p486;

public class PredictTheWinner {

    public static void main(String[] args) {
        PredictTheWinner obj = new PredictTheWinner();
        System.out.println(obj.PredictTheWinner(new int[]{1,7,5}));
    }

    public boolean PredictTheWinner(int[] nums) {
        int length = nums.length;
        int[][] dp = new int[length][length];
        for (int i = length-1; i >=0; i--) {
            dp[i][i] = nums[i];
            for (int j = i+1; j < length; j++) {
                dp[i][j] = Integer.max(nums[i] - dp[i+1][j],nums[j] - dp[i][j-1]);
            }
        }
        return dp[0][length-1] >= 0;
    }
}